package gui.panels.statistics;

import java.awt.Color;
import java.util.Map;
import java.util.Map.Entry;

import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

public class MostPlayedPanel extends JPanel implements StatisticsContent {

    private static final long serialVersionUID = 1L;

    private Map<String,Integer> mostPlayed;    
    
    public MostPlayedPanel(Map<String, Integer> mostPlayed) {
        
        this.mostPlayed = mostPlayed;
        
        setBackground(Color.WHITE);
        
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        String columnKey = "";
        
        for(Entry<String,Integer> entry : this.mostPlayed.entrySet()) {
            dataset.addValue(entry.getValue(), entry.getKey(), columnKey);
        }
        
        JFreeChart chart = ChartFactory.createBarChart3D(null, "Character", "Times chosen", dataset, PlotOrientation.VERTICAL, true, false, false);
        ChartPanel panel = new ChartPanel(chart);
        panel.setBorder(new EmptyBorder(0,80,0,80));
        
        add(panel);
        setVisible(true);
    }

    @Override
    public String getTitle() {
        return "Most Played";
    }

    @Override
    public JPanel getContent() {
        return this;
    }

    @Override
    public String getIconName() {
        return "Chart_bar.png";
    }
    
    
}